package com.booklove.domain.po;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.time.LocalDateTime;
import java.io.Serializable;

import com.booklove.constant.OrderTypeConstant;
import com.booklove.constant.OrdersStateConstant;
import com.booklove.domain.dto.OrdersFormDonateDTO;
import com.booklove.domain.dto.OrdersFormTakeDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

/**
 * <p>
 * 订单列表
 * </p>
 *
 * @author author
 * @since 2024-09-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("orders")
@ApiModel(value = "Orders对象", description = "订单列表")
public class Orders implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("订单的接收者的自动生成的商户id")
    private Integer userShopId;

    @ApiModelProperty(value = "订单属于的用户")
    private Integer userId;

    @ApiModelProperty(value = "订单对应的笔记id")
    private Integer noteId;

    @ApiModelProperty(value = "许愿书本的id")
    private Integer wishBookId;

    @ApiModelProperty(value = "捐书id")
    private Integer donateBookId;

    @ApiModelProperty(value = "派送id")
    private Integer deliverId;

    @ApiModelProperty(value = "订单类型：0-捐赠或是1-许愿")
    private Integer orderType;

    @ApiModelProperty(value = "订单的状态-0-待接单-1-派送还是2-送达")
    private Integer orderState;

    @ApiModelProperty(value = "创建人")
    private Integer createdBy;

    @ApiModelProperty(value = "创建时间")
    private LocalDateTime createdTime;

    @ApiModelProperty(value = "更新人")
    private Integer updatedBy;

    @ApiModelProperty(value = "更新时间")
    private LocalDateTime updatedTime;


    public static Orders createDonateOrder(OrdersFormDonateDTO ordersFormDonateDTO) {
        // 赋值
        Orders orders = new Orders();
        orders.setWishBookId(ordersFormDonateDTO.getWishBookId());
        orders.setOrderState(OrdersStateConstant.WAITING_DELIVERY);

        // 时间创建
        orders.setCreatedTime(LocalDateTime.now());
        orders.setUpdatedTime(LocalDateTime.now());

        //类型
        orders.setOrderType(OrderTypeConstant.IS_DONATE);


        return orders;
    }


    public static Orders createTakeOrder(OrdersFormTakeDTO ordersFormTakeDTO) {
        // 赋值
        Orders orders = new Orders();
        orders.setDonateBookId(ordersFormTakeDTO.getDonateBookId());
        orders.setOrderState(OrdersStateConstant.WAITING_DELIVERY);

        // 时间创建
        orders.setCreatedTime(LocalDateTime.now());
        orders.setUpdatedTime(LocalDateTime.now());

        //类型
        orders.setOrderType(OrderTypeConstant.IS_TAKE);
        return orders;
    }


}
